﻿using log4net.Appender;
using log4net.Config;
using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace PcaWeb
{
    public class Log4netConfig
    {
        public static void InitializeLog4Net()
        {
            //Configurar log4net para usar webconfig
            XmlConfigurator.Configure();

            Hierarchy hier = log4net.LogManager.GetRepository() as Hierarchy;
            if (hier != null)
            {
                AdoNetAppender adoAppender = (from appender in hier.GetAppenders()
                                              where appender.Name.Equals("AdoNetAppender", StringComparison.InvariantCultureIgnoreCase)
                                              select appender).FirstOrDefault() as AdoNetAppender;

                if (adoAppender != null && adoAppender.ConnectionString.Contains("{auto}"))
                {
                    adoAppender.ConnectionString = PcaCore.DAL.Core.GetConnectionString();

                    adoAppender.ActivateOptions();
                }
            }
        }
    }
}